<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>props细节</h1>
    <p>当 prop 验证失败的时候，(开发环境构建版本的) Vue 将会产生一个控制台的警告。</p>
    <p>注意：不要尝试在子组件中修改props中的参数值，在vue3.0之后会报错（无法修改）。</p>
    <template id="temp1">
        <section>
            <p>{{name}}</p>
            <p>{{num}}</p>
            <p>{{person.value}}</p>
            <button @click="handleClick">点击我</button>
            <button @click="handleClick2">点击我2</button>
        </section>
    </template>
    <main id="app">
        <p>父组件num值：{{num}}</p>
        <p>父组件person.value值：{{person.value}}</p>
        <my-com :num="num" :person="person"></my-com>
    </main>
</body>
<script src="../vue.js"></script>
<script>
    new Vue({
        el: "#app",
        data() {
            return {
                num: 1,
                person: {
                    value: 1
                }
            }
        },
        components: {
            "my-com": {
                template: "#temp1",
                props: {
                    name: {
                        // type限定类型
                        type: [String,Number],
                        // 是否必传：默认false
                        required: true,
                        // 没有传递时的默认值
                        default: "Hydra"
                    },
                    num: {
                        type: Number,
                        default: 10
                    },
                    person: Object
                },
                methods: {
                    handleClick() {  
                        console.log(this.num);
                        this.num ++;
                    },
                    handleClick2() {
                        this.person.value ++;
                    },
                }
            },
        }
    })
</script>
</html>